import formJs from "./regexDetail.js"; //新增弹框配置项
import TableData from "@/components/public/el-table-pagination"; //列表

import {
    getFieldtestCheckWitnessPageList, //委托单编号
} from "@/api/request.js";

export default {
    props: [
        "dialogVisible", //弹框是否展示
        "dialogTitle", //标题
        "formData"
    ],
    data() {
        return {
            loading: false,
            visible: "", //弹框展示隐藏
            title: null, //弹框标题
            isLock: false, //取样按钮是否显示
            dialogHeight: null, //弹框高度
            btnShow: true,
            userInfo: {}, //登录用户
            // 列表
            getList: {
                fCompanyid: "", //左侧选中组织机构id
                userId: "", //查询待办或已办时传 列表页查询不传
                keyType: "", // 上方查询条件样品种类
                taskNumber: "", // 上方查询条件进场编号
                page: 1, //当前页码
                pageSize: 20, //每页显示条数
                modelType: "2", // 取样：0-待办 1-已办;收样：3-待办 4-已办；查看：传2
                startDates: "", //进场开始时间
                endDates: "", //进场结束时间
                fProjectposition: ""
            }, // 列表给后端传参
            table_config: formJs.table_config,
            tableData: [], //列表数据列表
            currentRow: null, //列表详情
            dataFid: null,//fid
            queryCriteriaData: {}, //分页
            // 列表
            formDatas:null

        };
    },
    components: {
        TableData,
    },
    watch: {
        dialogVisible: {
            handler(newVal) {
                if (newVal) {
                    this.visible = newVal;
                }
            },
            immediate: true,
        },
        dialogTitle: {
            handler(newVal) {
                if (newVal) {
                    this.title = newVal;
                }
            },
            immediate: true,
        },
        formData: {
            handler(newVal) {
                if (newVal) {
                    this.formDatas = newVal;
                }
            },
            immediate: true,
        },
    },
    created() {
        window.addEventListener("resize", this.getHeight);
        this.getHeight();
    }, //获取页面高度自适应：

    destroyed() {
        window.removeEventListener("resize", this.getHeight);
        this.getHeight();
    },
    mounted() {
        this.userInfo = JSON.parse(sessionStorage.getItem("GxBack-userInfo"));
        // console.log("this.userInfo", this.userInfo);
        this.btnShow = true;

        this.getList = {
            fCompanyid: "", //左侧选中组织机构id
                userId: "", //查询待办或已办时传 列表页查询不传
                keyType: "", // 上方查询条件样品种类
                taskNumber: "", // 上方查询条件进场编号
                page: 1, //当前页码
                pageSize: 20, //每页显示条数
                modelType: "2", // 取样：0-待办 1-已办;收样：3-待办 4-已办；查看：传2
                startDates: "", //进场开始时间
                endDates: "", //进场结束时间
                fProjectposition: ""
        }
        this.yj_searchForm(this.getList) // currentRow
        this.getHeight();

        // this.table_config.operation.cols = [
        //     {
        //         prop: "fStatus",
        //         type: "primary",
        //         handleRow: this.handleRow,
        //     },
        // ];
        // this.table_config.operation["specialClass"] = function (rowData) {
        //     var color = null;
        //     if (rowData == "编辑中") {
        //         color = "red !important";
        //     } else if (rowData == "已完成") {
        //         color = "green !important";
        //     } else {
        //         color = "#409eff !important";
        //     }
        //     return color;
        // };
    },
    methods: {
        getHeight() {
            var h = document.documentElement.clientHeight; //获取页面可见高度
            this.dialogHeight = h * 0.76 + "px";
        },
        closeDialog() {
            this.$emit("close");
        },
        edit() {
            this.formData = this.$options.data.call(this).formData;
        },

        // 获取列表数据
        yj_searchForm(id) {
        this.userInfo = JSON.parse(sessionStorage.getItem("GxBack-userInfo"));

            var obj = {
                fCompanyid: this.userInfo.fCompanyid, //左侧选中组织机构id
                userId: this.userInfo.userId, //查询待办或已办时传 列表页查询不传
                keyType: this.formDatas.fChecktype, // 上方查询条件样品种类
                taskNumber: "", // 上方查询条件进场编号
                page: id.page, //当前页码
                pageSize: 20, //每页显示条数
                modelType: "2", // 取样：0-待办 1-已办;收样：3-待办 4-已办；查看：传2
                startDates: "", //进场开始时间
                endDates: "", //进场结束时间
                fProjectposition: ""
            };
            this.loading = true;
            var that = this;
            getFieldtestCheckWitnessPageList(obj)
                .then((res) => {
                    if (res.errcode == 0) {
                        that.loading = false;
                        that.tableData = res.data.pageInfo.list;
                        this.queryCriteriaData = res.data.pageInfo;
                    } else {
                        this.$message.error("列表数据获取失败", res.msg);
                        this.loading = false;
                    }
                })
                .catch((error) => {
                    this.$message.error("列表数据 接口出错", error.msg);
                    this.loading = false;
                });
        },
        // 点击当前行
        rowChange(val) {
            this.currentRow = val;
            this.dataFid = val.fId;
            return val;
        },

        yj_saveForm() {
            if (this.currentRow != null && this.currentRow != "") {
                this.$emit("getEntrustRow", this.currentRow);
                this.closeDialog();
            } else {
                this.$message.warning("请先选择需要保存的数据");
            }
        },

    },
};